package com.simple.dispatcher.service;

import javax.annotation.PostConstruct;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import weibo4j.Status;
import weibo4j.Weibo;
import weibo4j.WeiboException;

/**
 * 微博信息的维护
 * @author 毛琦
 */
@Service
public class MyWeiboService {
	
	private final Log log = LogFactory.getLog(getClass());
	
	private Weibo weibo = null;
	
	@PostConstruct
	public void init() {
		weibo = new Weibo();
		weibo.setToken("eae6fd704cecbaf019dd8b1ed3cd092b", "24c90010795a7a951853407102f474cb");
	}
	
	/**
	 * 发布微博
	 * @return
	 */
	public long publishWeiBo(String message, String url) {
		try {
			Status status = weibo.updateStatus(message + "\n详情请访问：" + url);
			log.info("微博发布成功：" + status.getId());
			return status.getId();
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return 0;
	}
}
